package com.njegovanobradovic.icet.metamodel.beans;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Cascade;
import org.springframework.transaction.annotation.Transactional;

import com.njegovanobradovic.icet.core.beans.BaseBean;
import com.njegovanobradovic.icet.metamodel.Chat;
import com.njegovanobradovic.icet.metamodel.Message;

@Entity
public class MessageBean extends BaseBean implements Message {

	private Date date;
	private String content;
	private Chat chat;
	
	@Basic
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	@ManyToOne(cascade = {CascadeType.MERGE},
			targetEntity=ChatBean.class)
	public Chat getChat() {
		return chat;
	}
	public void setChat(Chat chat) {
		this.chat = chat;
	}
	public int compareTo(Message o) {
		MessageBean messageBean = (MessageBean) o;
		return getDate().compareTo(messageBean.getDate());
	}
}
